package com.gule.gl.leetcode.editor.javabook;

import com.gule.gl.leetcode.editor.cn.definition.TreeNode;

import java.util.Objects;

/**
 * @Auther: gl
 * @Date: 2020/2/12 16:52
 * @Description: 复制一颗二叉树
 */
public class CopyTree {

    TreeNode copyTree(TreeNode root) {
        if (Objects.isNull(root)) {
            return null;
        }
        TreeNode newRoot = new TreeNode(root.val);
        newRoot.left = copyTree(root.left);
        newRoot.right = copyTree(root.right);
        return newRoot;
    }
}
